from rest_framework import serializers
from workflow.models import (
    Workflow,
    WorkflowPermission,
    WorkflowApprovalNode,
    Task,
    AuditRecord
)
from admins.models import (
    RoleModel,
    AdminUserModel,
    Department,
    Position,
)
from admins.ser import (
    RoleSerializer,
    AdminUserSerializer,
    DepartmentSerializer,
    PositionSerializer
)

# 工作流序列化器
class WorkflowSerializer(serializers.ModelSerializer):

    class Meta:
        model = Workflow
        fields = ['id', 'name', 'params', 'status']

# 工作流权限序列化器
class WorkflowPermissionSerializer(serializers.ModelSerializer):
    role_id = serializers.IntegerField(source='role.id', read_only=True)
    workflow_id = serializers.IntegerField(source='workflow.id', read_only=True)
    class Meta:
        model = WorkflowPermission
        fields = ['id', 'role_id', 'workflow_id']

# 工作流审批节点配置序列化器
class WorkflowApprovalNodeSerializer(serializers.ModelSerializer):

    class Meta:
        model = WorkflowApprovalNode
        fields = ['id', 'workflow_id', 'position_id', 'level']

# 任务序列化器
class TaskSerializer(serializers.ModelSerializer):

    class Meta:
        model = Task
        fields = ['id', 'name', 'params', 'workflow', 'userid', 'next_audit', 'task_status', 'level']

# 审批记录序列化器
class AuditRecordSerializer(serializers.ModelSerializer):

    class Meta:
        model = AuditRecord
        fields = ['id', 'task', 'audit_user', 'audit_time', 'audit_status']